<?php
class ImageLists extends Action {
	private $limit = 20;
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$action = rqst ( "action" );
		$data = '';
		if ($action == "get") {
			$start = irqst ( 'pid', 1 ) - 1;
			$title = rqst ( 'title' );
			$ext = rqst ( 'type' );
			$where ['type'] = 'image';
			if (! empty ( $ext )) {
				$where ['ext'] = $ext;
			}
			if (! empty ( $title )) {
				$where ['name LIKE'] = "%$title%";
			}
			$month = rqst ( 'month' );
			$year = irqst ( 'year', 0 );
			if (! empty ( $month ) && empty ( $year )) { // 月不为空
				$year = date ( 'Y-' );
				$time1 = strtotime ( $year . $month . '-01' );
				$time2 = strtotime ( '+1 months -1 seconds', $time1 );
				$where ['create_time BETWEEN'] = array ($time1,$time2 );
			} elseif (! empty ( $year ) && empty ( $month )) {
				$time1 = strtotime ( $year . '-01-01' );
				$time2 = strtotime ( '+1 years -1 seconds', $time1 );
				$where ['create_time BETWEEN'] = array ($time1,$time2 );
			} elseif (! empty ( $month ) && ! empty ( $year )) {
				$time1 = strtotime ( $year . '-' . $month . '-01' );
				$time2 = strtotime ( '+1 months -1 seconds', $time1 );
				$where ['create_time BETWEEN'] = array ($time1,$time2 );
			}
			
			$atM = new WebAttachmentModel ();
			
			$atM->where ( $where )->limit ( $this->limit, $start )->count ( true, 'attachment_id' )->sortDesc ( 'create_time' );
			
			$files = $atM->retrieve ( 'url' );
			if ($files) {
				$data = ceil ( $files->countTotal / $this->limit ) . 'ue_page_ue' . $files->join ( 'url', false, 'ue_separate_ue' );
			}
		}
		echo $data;
	}
}